﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SWEN_HMS.Classes;

namespace SWEN_HMS.BookingModule
{
    public partial class RoomAvailiability : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["staffid"] == null)
            {
                Response.Redirect("~/UserModule/Login.aspx");
            }
            else if ((Convert.ToString(Session["accessLvl"])) == "No Access")
            {
                Response.Redirect("~/UserModule/Login.aspx");
            }

        }

        protected void checkIn_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/BookingModule/CheckInSearch.aspx");
        }

        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DataList1.SelectedValue != null)
            {
                Label2.Text = DataList1.SelectedValue.ToString();
            }
        }

        protected void request_Click(object sender, EventArgs e)
        {
            if (Label2.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("Select Room Number first");
            }
            else
            {
                string status = RoomDBManager.checkRoomStatus(Convert.ToInt32(Label2.Text));

                if (status == "Available")
                {
                    System.Windows.Forms.MessageBox.Show("Room is not vacant by anyone");
                }
                else if (status == "Occupied" || status == "Cleaning")
                {
                    string rm = Label2.Text;
                    string queryString = "Room=" + rm;
                    Response.Redirect("~/BookingModule/Request.aspx?" + queryString);
                }
            }
        }

        protected void checkOut_Click(object sender, EventArgs e)
        {
            string rm = Label2.Text;
            string queryString = "Room=" + rm;
            Response.Redirect("~/BookingModule/CheckOut.aspx?" + queryString);
        }

        protected void cleaning_Click(object sender, EventArgs e)
        {
            if (Label2.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("Select Room Number first");
            }
            else
            {
                string check = RoomDBManager.checkInStatus(Convert.ToInt32(Label2.Text));
                string result = RoomDBManager.checkRoomStatus(Convert.ToInt32(Label2.Text));

                if (check == "True")
                {
                    if (result == "Cleaning")
                    {
                        RoomDBManager.changeRoomStatus(Convert.ToInt32(Label2.Text), "Occupied");
                        System.Windows.Forms.MessageBox.Show("Cleaning completed");
                        Response.Redirect("~/BookingModule/RoomAvailability.aspx");
                    }
                    else if (result == "Available" || result == "Occupied")
                    {
                        System.Windows.Forms.MessageBox.Show("No cleaning was in progress");
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Guest has not check-in into the room");
                }
            }
        }
    }
}
